<?php 

/**
 * CoreController
 * @author lk
 */
class DilemaController extends My_Controller {

	/** Pytania */
	public function dilemaformAction(){
		echo $this->_helper->form(new Dilema());
	}
	
	public function dilemagridAction(){
		$this->_helper->grid(new Dilema());
	}
	
	public function dilemadelAction(){
		echo $this->_helper->delete(new Dilema());
	}
	
	/** Odpowiedzi */
	public function dilemapointformAction(){
		echo $this->_helper->form(new DilemaPoint());
	}
	
	public function dilemapointgridAction(){
		$this->_helper->grid(new DilemaPoint());
	}
	
	public function dilemapointdelAction(){
		echo $this->_helper->delete(new DilemaPoint());
	}
	
	/** Tagi*/
	public function dilematagformAction(){
		echo $this->_helper->form(new DilemaTag());
	}
	
	public function dilemataggridAction(){
		$this->_helper->grid(new DilemaTag());
	}
	
	public function dilematagdelAction(){
		echo $this->_helper->delete(new DilemaTag());
	}
	
	
/** Oceny */
	public function dilemapointrateformAction(){
		
		Utils::rq(array(
			'user_id'=>Utils::myId(),
			'dilema_point_rate_date'=>date('Y-m-d H:i:s'),
			'dilema_point_rate_ip'=> $_SERVER['REMOTE_ADDR']
		));
		
		echo $this->_helper->form(new DilemaPointRate());
	}
	
	public function dilemapointrategridAction(){
		$this->_helper->grid(new DilemaPointRate());
	}
	
	public function dilemapointratedelAction(){
		echo $this->_helper->delete(new DilemaPointRate());
	}
	
/** kontrargumenty */
	public function dilemapointcounterpointformAction(){
		echo $this->_helper->form(new DilemaPointCounterpoint());
	}
	
	public function dilemapointcounterpointgridAction(){
		$this->_helper->grid->_(array(
			'class'=>new DilemaPointCounterpoint(),
			'join'=>array(
				array('d'=>'dilema_point'),// ziarno które zmierza do destrukcji
				'(d.dilema_point_id = #.dilema_point_id OR d.dilema_point_id = #.counterpoint_id)',
				array(
					'GROUP_CONCAT(IF(d.dilema_point_id = dilema_point_counterpoint.counterpoint_id, d.dilema_point_side,"") SEPARATOR "") AS counter_side',
					'GROUP_CONCAT(IF(d.dilema_point_id = dilema_point_counterpoint.dilema_point_id, d.dilema_point_side,"") SEPARATOR "") AS point_side',
				
					'GROUP_CONCAT(IF(d.dilema_point_id = dilema_point_counterpoint.counterpoint_id, d.dilema_point_head,"") SEPARATOR "") AS counter_head',
					'GROUP_CONCAT(IF(d.dilema_point_id = dilema_point_counterpoint.dilema_point_id, d.dilema_point_head,"") SEPARATOR "") AS point_head',
				
					'GROUP_CONCAT(IF(d.dilema_point_id = dilema_point_counterpoint.counterpoint_id, d.dilema_point_body,"") SEPARATOR "") AS counter_body',
					'GROUP_CONCAT(IF(d.dilema_point_id = dilema_point_counterpoint.dilema_point_id, d.dilema_point_body,"") SEPARATOR "") AS point_body'
				),
				'left'
			),
			'group'=>'dilema_point_counterpoint_id'
		));
	}
	
	public function dilemapointcounterpointdelAction(){
		echo $this->_helper->delete(new DilemaPointCounterpoint());
	}
	
/** Filmy */
	public function dilemapointmovieformAction(){
		echo $this->_helper->form(new DilemaPointMovie());
	}
	
	public function dilemapointmoviegridAction(){
		
		$this->_helper->grid->_(array(
			'class'=>new DilemaPointMovie(),
			'join'=>array('movie','movie.movie_id = #.movie_id',array('*'),'left')
		));
		
	}
	
	public function dilemapointmoviedelAction(){
		echo $this->_helper->delete(new DilemaPointMovie());
	}
	
/** Cytaty */
	public function dilemapointquoteformAction(){
		echo $this->_helper->form(new DilemaPointQuote());
	}
	
	public function dilemapointquotegridAction(){
		$this->_helper->grid->_(array(
			'class'=>new DilemaPointQuote(),
			'joins'=>array(
				array(array('v'=>'verse'),'v.verse_number BETWEEN #.start_verse_number AND #.end_verse_number AND #.book_id = v.book_id AND #.chapter_id = v.chapter_id',array('*'),'left'),
				array(array('bv'=>'bible_verse'),'bv.verse_id = v.verse_id',array(
					'GROUP_CONCAT(IF(bv.bible_id = 1,CONCAT(" {",v.verse_number,"} ",bv.bible_verse_text,"<br/>"),"") SEPARATOR "") AS bible_1_text',
					'GROUP_CONCAT(IF(bv.bible_id = 3,CONCAT(" {",v.verse_number,"} ",bv.bible_verse_text,"<br/>"),"") SEPARATOR " ") AS bible_3_text'
				))
			),
			'group'=>'dilema_point_quote_id'
		));
	}
	
	public function dilemapointquotedelAction(){
		echo $this->_helper->delete(new DilemaPointQuote());
	}
	
	
	

}
